lunoschedule = { }

lunoschedule.getMineDays = function()
	local time_speed = minetest.setting_get("time_speed")
	if time_speed==nil or type(time_speed)~="number" or time_speed<1 then
		time_speed = 48
	end
	local gametime = minetest.get_gametime()
	local secoundsperday = 60*60*24/time_speed
	local mineDays = gametime/secoundsperday
	return mineDays
end

lunoschedule.getMineMounts = function()
	local mineDays = lunoschedule.getMineDays()
	return mineDays/28
end

lunoschedule.getMineMount = function()
	--math.ceil(arredonda para cima de 0.5), math.floor(arredonda para menor de 0.5)
	local mineDays = lunoschedule.getMineDays()
	--local dayofyear = mineDays%(28*4) 
	return math.ceil((mineDays/28)%4)
end

lunoschedule.getMineDay = function()
	--math.ceil(arredonda para cima de 0.5), math.floor(arredonda para menor de 0.5)
	local mineDays = lunoschedule.getMineDays()
	return math.ceil(mineDays%28)
end

lunoschedule.getMineDayRow = function()
	--math.ceil(arredonda para cima de 0.5), math.floor(arredonda para menor de 0.5)
	local mineDay = lunoschedule.getMineDay()
	return math.ceil(mineDay/7)
end

lunoschedule.getMineDayCol = function()
	local mineDay = lunoschedule.getMineDay()
	local nowRow = lunoschedule.getMineDayRow()
	return mineDay-((nowRow-1)*7)
end

lunoschedule.doUpdateBlockSchedule = function(pos)
	local lado = minetest.get_node(pos).param2
	local mineDays = lunoschedule.getMineDays()
	local nowMes = lunoschedule.getMineMount()
	local nowDia = lunoschedule.getMineDay()
	local nowRow = lunoschedule.getMineDayRow()
	local nowCol = lunoschedule.getMineDayCol()
	minetest.env:add_node(pos, {name="lunoschedule:schedule_"..nowMes.."_"..nowDia})
	local node = minetest.get_node(pos)
	node.param2 = lado
	minetest.swap_node(pos, node)
	--[[
	minetest.env:get_meta(pos):set_string(
		"infotext", "mes="..nowMes.." dia="..nowDia
		.." dias="..mineDays.." Row="..nowRow.." Col="..nowCol
	)
	]]--
end


